{extend name="/fool" /}
{block name="css"}
<link rel="stylesheet" href="/css/admin/userindex.css">
<style>
    .layui-form-onswitch{
        /*background: #1989FA;*/
        /*border-color: #1989FA;*/
    }
    #page{
        position: relative;
        display: inline-block;
        left:30%;
        margin-left:-50px;
        padding:50px 0;
    }
    .qrk{
        background: #fff;
        display:none;
        width: 300px;
        height:220px;
        border:1px solid #000;
        position: absolute;
        left:50%;
        margin-left:-150px;
        margin-top:-110px;
        top:40%;
        border-radius: 10px;
        z-index: 999;
    }
</style>
{/block}
{block name="menu_content"}
<div class="qrk">
    <div style="text-align: center;line-height: 50px;font-size: 20px;">主账号设置</div>
    <div style="text-align: center;margin:10px 0 30px 0;">
        是否设置该用户为主账号<br>
        设置后你将失去主账号权限<br>
        设置后将强制重新登录账号
    </div>
    <div>
        <button type="button" class="qx layui-btn" style="float: left;margin-left: 45px;">取消</button>
        <button type="button" class="qr layui-btn" style="float: right;margin-right: 45px;">确认</button>
    </div>
</div>
<div id="one">
    <form class="layui-form" action="" method="post">
        <ul>
            <li>
                <div class="layui-input-inline">
                    <input type="text" name="name" autocomplete="off" class="layui-input" placeholder="使用人">
                </div>
                <button type="Submit" class="layui-btn">筛选</button>
            </li>
        </ul>
    </form>
</div>
<div>
    <form class="layui-form" action="" method="post">
        <table>
            <tr>
                <th>操作日期</th>
                <th>账号</th>
                <th>使用人</th>
                {if $login['master'] == 2}
                <th class="last" style="width:30%;">操作</th>
                {else}
                <th class="last">操作</th>
            	{/if}
            </tr>
            {if isset($list)}
            {foreach $list as $v}
            <tr class="list">
                <td class="name">{$v.create_time}</td>
                <td class="phone">{$v.username}</td>
                <td class="region">{$v.name}</td>
                <td>
                	{if $v.username != 'admin'}
                    <button sid="{$v.id}" type="button" class="delete layui-btn">删除</button>
                    <button sid="{$v.id}" type="button" class="bj layui-btn">编辑</button>
                    {/if}
                    {if $login['master'] == 2 && $v.username != 'admin'}
                    {if $v.master != 2}
                    <button sid="{$v.id}" type="button" class="zzh layui-btn">设为总账号</button>
                    {else}
                    <button sid="{$v.id}" type="button" class="layui-btn layui-btn-normal">总账号</button>
                    {/if}
                    {/if}
                </td>
            </tr>
            {/foreach}
            {/if}
        </table>
    </form>
    <div id="page">
        {if isset($list)}
        {$page|raw}
        {/if}
    </div>
</div>
<script>
	var sid = 0;
	$(".zzh").click(function(){
		$(".qrk").show();
		sid = $(this).attr('sid');
	})
	$(".qx").click(function(){
		$(".qrk").hide();
	})
	$(".qr").click(function(){
		console.log(sid);
		$.post("{:url('zzh')}",{
			id:sid
		},function(res){
			console.log(123);
			top.location.href = "https://baosheng.langqiyun.cn/admin/user/login";
		},'json')
		$(".qrk").hide();
	})
    $(".bj").click(function(){
        var id = $(this).attr('sid');
        var url = "{:url('setting',['id'=>9,'index'=>'1'])}" + "&sid=" + id;
        location.href = url;
    })
    $(".delete").click(function(){
        var id = $(this).attr('sid');
        $.post("{:url('delete')}",{id},function(res){
            console.log(res);
            history.go(0);
        },'json');
    })
    layui.use('form', function(){
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#test1'
            ,type: 'month'
            ,range: '至'
            ,format: 'yyyy-MM'
        });
    });
    layui.use('laypage', function(){
        var laypage = layui.laypage;
        //执行一个laypage实例
        laypage.render({
            elem: 'page'
            ,count: "{$count}"
            ,curr:"{$curl}"
            ,last:"{$groups}"
            ,limit:"{$limit}"
            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            ,jump: function(obj,first){
                console.log(obj)
                if(!first){
                    var url = "{:url('indexs',['id'=>5,'index'=>0])}" + '&page=' + obj.curr + '&limit=' + obj.limit + '&curr=' + obj.curr;
                    location.href = url;
                }
            }
        });
    });
</script>
{/block}